{extend name="extra@admin/content"}
{block name="content"}
<form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='form-horizontal' style='padding-top:20px'>
    <div class="">
        <div class="layui-fluid setlaytomartial">  
           {foreach $list as $key=>$vo}
              <div class="layui-row">
                <div class="layui-col-md3">
                     <label class="layui-form-label">数量</label>
                     <input type="text" name="num[{$key}]" value="{$vo['num']}">
                </div>
                <!-- <div class="layui-col-md3">
                    <label class="layui-form-label">备注</label> 
                    <input type="text" name="remark[{$key}]" value="{$vo['remark']}">
                </div> -->
                <div class="layui-col-md3">
                     <label class="layui-form-label">配方</label>
                     <div class="layui-form-item">
                        <div class="layui-input-block">
                         <select name ="sele[{$key}]" lay-verify="" style="margin-left: 10px">
                             <option value="{$vo['marid']}">{$vo['name']} </option> 
                                 {foreach($matelist as $key1)}
                                    <?php if($key1['id']==$vo['marid']): continue; ?>
                                    <?php endif;?>
                                    <option value="{$key1['id']}">{$key1['name']} </option>
                                 {/foreach}          
                         </select>
                        </div>
                      </div>
                </div>
                <input type="hidden" name="isd[{$key}]" value="{$vo['id']}">
                <a data-modal='{:url("$classuri/dele_pecipe")}?id={$vo.id}' href="javascript:void(0)">删除配方</a>
              </div>
            {/foreach}
        </div>
    </div>
    <div class="hr-line-dashed"></div>
        <div class="col-sm-4 col-sm-offset-2">
           <input type='hidden' value='{$idse}' name='id'/>
           <input type='hidden' value='{$goodsid}' name='goodsid'/>
           
        <div class="layui-form-item text-center">
            <span class="layui-btn tianjiayihan" type="btn">添加配料</span>
            <button class="layui-btn" type="submit">保存配置</button>
        </div>
    </div>
</form>
 <style>
     .ibox-content{
            overflow-y: scroll;
    overflow-x: hidden;
    height: 500px;
     }
 </style>
 <script type="text/javascript">
      var  json = '<?php echo $matelistcn?>';
        require(['jquery'], function () {
             var ii=100;
             $('.tianjiayihan').click(function(event) {
                ii++;
                var optionshtml =  addoption(json,ii);
                $('.setlaytomartial').append(optionshtml);
            });
           
            function addoption(json,ii){
                   var html =  '';
                    html+='<div class="layui-row">'
                    html+='   <div class="layui-col-md3">'
                    html+='        <label class="layui-form-label">数量</label>'
                    html+='       <input type="text" name="num['+ii+']" value="">'
                    html+='    </div>'
                    // html+='    <div class="layui-col-md3">'
                    // html+='        <label class="layui-form-label">备注</label>' 
                    // html+='        <input type="text" name="remark['+ii+']" value="">'
                    // html+='    </div>'
                    html+='    <div class="layui-col-md3">'
                    html+='        <label class="layui-form-label">配方</label>'     
                    html+='         <div class="layui-form-item">'
                    html+='            <div class="layui-input-block">'
                    html+=                  select(json,ii);
                    html+='            </div>'
                    html+='          </div>'
                    html+='    </div>'

                    html+='    <div class="layui-col-md3">'
                    html+='        <label class="layui-form-label">操作</label>'    
                    html+='         <div class="layui-form-item">'
                    html+='            <div class="layui-input-block layui-btn" onclick="delecaozuo(this)">'
                    html+=              '删除'
                    html+='            </div>'
                    html+='          </div>'
                    html+='    </div>'

                    html+='    <input type="hidden" name="isd['+ii+']" value="999">'
                    html+='  </div>'

                return html;
            }
            function select(json,ii){
                jsonht = $.parseJSON(json);
                    var  html1 ='';
                    html1 +='<select name ="sele['+ii+']" lay-verify="">'
                    for (var i = jsonht.length - 1; i >= 0; i--) {
                       // console.dir(jsonht[i].id);
                       html1+='<option value="'+jsonht[i].id+'">'+jsonht[i].name+' </option> ' 
                    }
                              
                    html1+='</select>';

                    return html1
            }

           

        })

        function delecaozuo($this){
           $this.parentNode.parentNode.parentNode.parentNode.removeChild($this.parentNode.parentNode.parentNode);
        }
 </script>
{/block}